package Command;

import java.util.ArrayList;


import Algo.Algo;
import DataBase.MenuTag_File;
import DirectsDB.MenuDirects;

/**
* Description : this class is init the programe
* <p>
*
*@author Danielle
*/
public class Init {

	private MenuTag_File dataBase;
	private MenuDirects dirDB;
	private Thread thread;
	private boolean firstTime=true;
	ArrayList<Algo>  algoList;
	
	/**
	* Description initial the paraneters 
	* @param MenuTag_File dataBase
	* @param MenuDirects dirDB
	* @param ArrayList<Algo>  algo
	*/
	public void startParam(MenuTag_File dataBase, MenuDirects dirDB,ArrayList<Algo>  algo)
	{
		///initial all the parameters
		this.dataBase=dataBase;
		this.dirDB=dirDB;
		algoList=algo;
		///initial the thread
		thread= new threadOfInit(dataBase,dirDB,algoList); 
		
	}
	
	/**
	* Description stop the thread of init:
	*/
	public void stopInit()
	{
		((threadOfInit) thread).die();
	}
	
	/**
	* Description start the thread of init
	*/
	public void start()
	{
		//if this is the first run :
		if(firstTime)
		{
			//start new thread:
			thread= new threadOfInit(dataBase,dirDB,algoList);
			thread.start();
			//sign that this was the first time
			firstTime=false;
		}
		else
		{
			//kill the thread:
			((threadOfInit) thread).die();
			//start again a new one
			thread=new threadOfInit(dataBase,dirDB,algoList); 
			thread.start();
//			firstTime=true;
		}
		
	}
	
	/**
	* Description continue the thread- if it was started
	*/
	public void cont()
	{
		((threadOfInit) thread).cont();
	}
	
	
	/**
	* Description pause the thread of init:
	*/
	public void pause() {
		((threadOfInit) thread).pause();
		
	}
	
	/**
	* Description return the percent of the work
	* @return int
	*/
	public int getPrecent() {
		return ((threadOfInit) thread).getPrecent();
		
	}
}
